package cn.edu.zknu.mita.controller;

import cn.edu.zknu.mita.model.FindMsg;
import cn.edu.zknu.mita.service.ICategoryService;
import cn.edu.zknu.mita.service.IFindMsgService;
import cn.edu.zknu.mita.util.MessageTypeUtils;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * Created by iwlnner on 2020/3/26.
 */
@Controller
public class DetailController {

    @Autowired
    private IFindMsgService findMsgService;
    @Autowired
    private ICategoryService categoryService;


    @RequestMapping("/detail")
    public String detail(Long id, Model model){
        FindMsg msg=findMsgService.getDetail(id);
        if(msg!=null){
            String category = categoryService.convertCategory(msg.getCategory());
            msg.setCategory(category);
            model.addAttribute("msg",msg);
            model.addAttribute("type", MessageTypeUtils.getMessageTypeStr(msg.getType()));
        }
        return "detail";
    }

    @RequestMapping("hello")
    public String hello(Integer pageNum,Integer pageSize,Integer type,Model model){
        PageInfo<FindMsg> info = findMsgService.listFindMsg(pageNum, pageSize, type);
        model.addAttribute("info",info);
        return "hello";
    }
}
